package Day03;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Scanner;

@Data
@AllArgsConstructor
@NoArgsConstructor
class Student {
    private Integer id;
    private String name;
    private String password;
    private Integer age;
    private String gender;
}

class StudentService {
    public static Student[] students;

    static {
        students = new Student[3];
        students[0] = new Student(1, "HanserOne", "aaa", 11, "male");
        students[1] = new Student(2, "HanserTwo", "bbb", 12, "female");
        students[2] = new Student(3, "HanserThree", "ccc", 13, "male");
    }

    public static Student StudentLogin(String name, String password) {
        for (Student student : students) {
            if (student.getName().equals(name)) {
                if (student.getPassword().equals(password)) {
                    return student;
                } else {
                    throw new RuntimeException("密码错误！");
                }
            } else {
                throw new RuntimeException("用户不存在！");
            }
        }
        return null;
    }

}

public class HomeWork {
    public static void main(String[] args) {
        // 输入用户名，密码，验证
        Scanner sc = new Scanner(System.in);
        System.out.println("输入用户名:");
        String name = sc.next();
        System.out.println("输入密码:");
        String password = sc.next();
        // 登录成功，进入系统，登录失败，提示错误信息:(用户名不存在，密码错误)
        try {
            Student student = StudentService.StudentLogin(name, password);
            System.out.println("登录成功");
            System.out.println(student);
        } catch (Exception e) {
            System.out.println("登录失败：" + e.getMessage());
        }
    }
}
